package com.zjpavt.client.command;

import com.zjpavt.client.command.entity.BaseCommand;
import com.zjpavt.client.extenddevice.networkdevice.SuiteDeviceOnline;
import com.zjpavt.client.nativemethod.JnIMethod;
import com.zjpavt.client.util.PropertiesUtil;
import com.zjpavt.client.util.StringUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class KCommandExecutor {
    public static int dataTransformLength;

    static {
        try {
            dataTransformLength = Integer.parseInt(PropertiesUtil.getPropertiesDefault("kCommandTransformLength", "8"));
        } catch (IOException e) {
            e.printStackTrace();
            dataTransformLength = 8;
        }
    }

    /**
     * 取倒数第六位为是否进行强电控制
     * 倒数第五位为是否进行弱电控制
     * 最后八位为二进制的场景名称：
     * @param command
     * @return 返回true的时候继续解析k指令 否则结束该指令
     * 6.18——zj修改：把最后四位改成八位为二进制的场景名称
     */
    public static boolean hangZhouShow(String command) {
        log.info("hangzhoushow " + command);
        int length = command.length();
        char kUSe = command.charAt(length - dataTransformLength -2);
        char sceneUse = command.charAt(length - dataTransformLength - 1);
        String scene = command.substring(length - dataTransformLength, length);
        int sceneId = Integer.parseInt(scene, 2);
        if (sceneUse == '1') {
            SuiteDeviceOnline.sendSuiteScene(sceneId);
        } else {
//            donothing
        }
        if (kUSe == '1') {
//            String command512 = command.substring(length - dataTransformLength - 2 - 4, length - dataTransformLength - 2);
//            BaseCommand baseCommand = new BaseCommand(StringUtil.commandStr2Int(command512));
//            log.info("change 512 device " + command512);
//            int[] baseCommand1 = {0xff,0xff,0xff,0xff,0xff,0xff};
//            System.arraycopy(baseCommand.getCommand512(),0,baseCommand1,1,baseCommand.getLength());
//            JnIMethod.sendDMX512Signal(baseCommand1, 1);
            return true;
        } else {
            return false;
        }
    }

    /*    public static boolean yaolingxianjingShow(String command) {
            int length = command.length();
            char kUSe = command.charAt(length - 6);
            char sceneUse = command.charAt(length - 5);
            String scene = command.substring(length - 4, length);
            int sceneId = Integer.parseInt(scene, 2);
            if (sceneUse == '1') {
                SunLightDeviceOnline.sendSuiteScene(sceneId);
            }else {
    //            donothing
            }
            if (kUSe == '1') {
                return true;
            } else {
                return false;
            }
        }*/
}
